import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    // 数据更新
    updataKey:0,
    // 登录按钮
    isLogin:false,
    // 登录框
    isShowLogin: false,
    // 按钮禁用
    dengdisabled:false,
    // 我的积分
    myChicken:'--',
    
    // 输入框内容，
    inpVal:'',
    toast: {
      isTishi: false,
      tishiVal: '',
      icon: ''
    },
    // 获取的商品数据
    itemsData:[],
    // 请求发送的商品信息
    items:{
      min: 0,
      max: 0,
      type: 0,
      keyword:''
    }

  },
  getters: {
  },
  mutations: {
    changeIsShowLogin(state, p) {
      state.isShowLogin = p
    },
    changeisTishi(state, payload) {
      state.toast.isTishi = true
      state.toast.tishiVal = payload.value
      state.dengdisabled = true
      switch(payload.icon){
        case "info":
          state.toast.icon = "icon-toast-jinggao";
          break;
        case "success":
          state.toast.icon = "icon-toast_chenggong";
          break;
        case "danger":
          state.toast.icon = "icon-toast-shibai_huaban";
          break;
        case "loading":
          state.toast.icon = "icon-loading";
          break;
        default:
          state.toast.icon = "icon-toast-jinggao";
          break;
      }
    },changeitems(state,payload){
      let arr = Object.keys(payload)
      arr.forEach(item=>{
        if(state.items.hasOwnProperty(item)){
          state.items[item] = payload[item]
        }
      })

    },
    closeToast(state){
      state.toast.isTishi = false
      state.dengdisabled = false
    },changeitemsData(state,payload){
      this.changeitemsData = payload
    }
  },
  actions: {
    AsyncToast({
      commit
    }, payload) {
      commit('changeisTishi', payload);
      setTimeout(() => {
        commit('closeToast')
      }, 2000)
    }
  },
  modules: {
  }
})
